package com.wpzf.zxhc.service.impl;

import com.wpzf.zxhc.mapper.WpzfJlHcTaskMapper;
import com.wpzf.zxhc.mapper.WpzfShTbMapper;
import com.wpzf.zxhc.service.CommonService;
import com.wpzf.zxhc.service.WpzfJlHcTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class WpzfJlHcTaskServiceImpl implements WpzfJlHcTaskService {

    @Autowired
    WpzfJlHcTaskMapper wpzfJlHcTaskMapper;

    @Autowired
    WpzfShTbMapper wpzfShTbMapper;

    @Override
    public int addTask(Map<String, Object> map) {
        return wpzfJlHcTaskMapper.addTask(map);
    }

    @Override
    public List<Map<String, Object>> query_tbbhsfkc(Map<String, Object> map) {
        return wpzfJlHcTaskMapper.query_tbbhsfkc(map);
    }

    @Override
    public Map<String, Object> query_tbbh_id(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_tbbh_id(parm);
    }

    @Override
    public int deleteTbbh(Map<String, Object> map) {
        return wpzfJlHcTaskMapper.deleteTbbh(map);
    }

    @Override
    public List<Map<String, Object>> query_jl_w_task(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_w_task(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_wf_task(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_qt_task(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_w_task(parm);
    }

    @Override
    public Integer query_jl_w_task_count(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_w_task_count(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_wf_task_count(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_qt_task_count(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_w_task_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_w_task_list(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_w_task_list(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_wf_task_list(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_qt_task_list(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_w_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_w_left_task_list(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_w_left_task_list(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_wf_left_task_list(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_w_qt_left_task_list(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_w_left_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_y_left_task_list(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_y_left_task_list(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_wf_left_task_list(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_qt_left_task_list(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_y_left_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_wwc_Provs(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_wwc_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_wwc_Citys(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_wwc_Citys(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_y_task(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_y_task(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_wf_task(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_qt_task(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_y_task(parm);
    }

    @Override
    public Integer query_jl_y_task_count(Map<String, Object> parm) {
        if (("全部").equals(parm.get("pdlxEj").toString())) {
            return wpzfJlHcTaskMapper.query_jl_y_task_count(parm);
        } else {
            if (("违法").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_wf_task_count(parm);
            } else if (("其他").equals(parm.get("pdlx").toString())) {
                return wpzfJlHcTaskMapper.query_jl_y_qt_task_count(parm);
            }
        }
        return wpzfJlHcTaskMapper.query_jl_y_task_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_y_task_list(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_y_task_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_ywc_Provs(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_ywc_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_ywc_Citys(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_ywc_Citys(parm);
    }

    @Override
    public int updateSubmit(Map<String, Object> map) {
        return wpzfJlHcTaskMapper.updateSubmit(map);
    }

    @Override
    public int updateJlSubmit(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.updateJlSubmit(parm);
    }

    @Override
    public int updateTbbh(Map<String, Object> parm) {
        try {
            //region 1  分配的判断条件 数量和单位
            List<Map<String, Object>> userlist = (List<Map<String, Object>>) parm.get("userlist");
            int rs = userlist.size();//人数
            int fpcount = Integer.parseInt(parm.get("count").toString()); //每人多少个
            int zcount = rs * fpcount;  //所需要的总个数
            if (zcount > Integer.parseInt(parm.get("zcount").toString())) {
                return -1;
            }
            //返回单位及目前总数量 count
            List<Map<String, Object>> dwlists = wpzfJlHcTaskMapper.getdwmcinfo(parm);
            if (dwlists == null || dwlists.size() == 0) {
                return -2;
            }
            //endregion

            //region 2  获取所有监理信息 单位信息 fpcount 分配数量 tblist 需要划分的tbbh列表
            parm.put("userlist", userlist);
            List<Map<String, Object>> userlists = wpzfJlHcTaskMapper.getuserinfo(parm);
            List<String> userdwlist = new ArrayList<String>();// 查询 用户涉及多少单位
            List<String> alldwlist = new ArrayList<String>();// 查询 所有单位list
            for (int i = 0; i < userlists.size(); i++) {
                List<String> list1 = new ArrayList<String>();
                Map<String, Object> model = userlists.get(i);
                String dwmc = model.get("dwmc").toString();
                //不包含单位名称 则添加单位   获取用户单位信息
                if (!userdwlist.contains(dwmc)) {
                    userdwlist.add(dwmc);
                }
                model.put("tblist", list1);
            }
            //endregion

            //如果用户单位少于 dwlists.size()
            Boolean flag = false;
            String dw = "";
            if (userdwlist.size() < dwlists.size()) {
                if (userdwlist.size() == 1)  //分配用户 涉及单位只有一个
                {
                    for (int c = 0; c < dwlists.size(); c++) {
                        if (dwlists.get(c).get("dwmc").equals(userdwlist.get(0))) //用户单位为三家单位其中一个
                        {
                            flag = true;
                            dw = dwlists.get(c).get("dwmc").toString();
                            break;
                        }
                    }
                    if (flag)  //则从list中去除 该单位
                    {
                        ListIterator<Map<String, Object>> iterator = dwlists.listIterator();
                        while (iterator.hasNext()) {
                            if (iterator.next().get("dwmc").toString().equals(dw)) {
                                iterator.remove();
                                break;
                            }
                        }

                    }
                }
            }


            //region 3 从各单位获取对应数量的数据  不足平均值的 后面的补齐 count 总数量  sl 从单位抽取多少
            int avgcount = zcount / (dwlists.size()); //按照单位个数 平均分配数量情况 每家单位拿多少
            int yscount = zcount % (dwlists.size()); //划分不平衡的余数
            if (avgcount <= Integer.parseInt(dwlists.get(0).get("count").toString())) //比较最小数量和平均数量
            {
                for (int i = 0; i < dwlists.size(); i++) {
                    if (i == dwlists.size() - 1) {
                        dwlists.get(i).put("sl", avgcount + yscount); //平均+余数 获取即可
                    } else {
                        dwlists.get(i).put("sl", avgcount); //平均 获取即可
                    }
                }
            } else {
                int ccount = 0;
                for (int i = 0; i < dwlists.size(); i++) {
                    String dwmc = dwlists.get(i).get("dwmc").toString();//单位名称
                    int count = Integer.parseInt(dwlists.get(i).get("count").toString());//单位所拥有个数 100
                    if (count <= avgcount) //个数不够平均值 100
                    {
                        dwlists.get(i).put("sl", count); //只能获取 这些数量的值 100
                        ccount += count;
                    } else {
                        if (ccount != avgcount * i) {
                            if (count <= avgcount + (avgcount * i - ccount)) {
                                dwlists.get(i).put("sl", count); //只能获取 这些数量的值 100
                                ccount += count;
                            } else {
                                dwlists.get(i).put("sl", avgcount + (avgcount * i - ccount));//补齐前面的
                                ccount += avgcount + (avgcount * i - ccount);
                            }
                        } else {
                            dwlists.get(i).put("sl", avgcount); //给平均值即可
                            ccount += avgcount;
                        }
                    }
                }
            }
            //endregion

            //region 4 获取后 按单位分配 不能分配给本单位人员
            int fpgs = 0; //平均分配个数
            int qt = 0;
            for (int i = 0; i < dwlists.size(); i++)  //循环单位  i=0 fpcount都为0
            {
                String dwmc = dwlists.get(i).get("dwmc").toString();//单位名称
                int sl = Integer.parseInt(dwlists.get(i).get("sl").toString());//从该单位获取的数量
                parm.put("dwmc", dwmc);
                parm.put("value", sl);
                List<String> dwlist = wpzfJlHcTaskMapper.getdwList(parm); //按照 dwmc sl获取对应的tbbh条数
                //是否有带-的数据 正好截取到带-的位置
                List<String> qclist = new ArrayList<>();
                String str = "";
                for (int mj = dwlist.size() - 1; mj > -1; mj--) {
                    String lastone = dwlist.get(mj).toString();
                    if (!lastone.contains("-")) {
                        break;
                    } else {
                        //最后一个带  - 则查找其他带-是否与最后一个一样 若一样则去掉
                        if (mj == dwlist.size() - 1) {
                            qclist.add(lastone);
                            str = lastone.split("-")[0].toString();
                        } else {
                            if (lastone.contains(str)) {
                                qclist.add(lastone);

                            } else {
                                break;
                            }
                        }
                    }
                }
                if (dwlist.size() == qclist.size()) {

                } else {
                    dwlist.removeAll(qclist);
                }
                sl = dwlist.size();
                //补齐 没分配的人员
                int jg = 0;
                if (qt != 0) {
                    for (int k = 0; k < userlists.size(); k++) {
                        Map<String, Object> model = userlists.get(k);
                        if (Integer.parseInt(model.get("fpcount").toString()) < qt && !model.get("dwmc").toString().equals(dwmc)) {
                            List<String> list1 = (List<String>) model.get("tblist");
                            int cz = qt - Integer.parseInt(model.get("fpcount").toString()); //差100
                            String[] arr = (String[]) dwlist.subList(jg, jg + cz).toArray(new String[dwlist.subList(jg, jg + cz).size()]);
                            Collections.addAll(list1, arr);
                            model.put("fpcount", Integer.parseInt(model.get("fpcount").toString()) + fpgs);
                            jg += cz;
                        }
                    }
                }

                List<Map<String, Object>> fhlist = GetUser(userlists, dwmc); //查询到符合条件得用户
                //List<User> fhlist=jllists.stream().filter(s->s.getDepartMent()!=dwmc).collect(Collectors.toList()); //获取不等于当前单位得用户
                if (fhlist.size() > 0 && sl != 0) {

                    fpgs = (sl - jg) / fhlist.size();  //整数
                    qt += fpgs;  //累加
                    int ys = (sl - jg) % fhlist.size();  //余数
                    int lastcount = fpgs;
                    if (ys != 0) //正常除不尽
                    {
                        lastcount = fpgs + ys;
                    }
                    int current = 0;
                    List<String> listA = dwlist.subList(jg + current * fpgs, jg + (current + 1) * fpgs);
                    for (int j = 0; j < userlists.size(); j++) {
                        Map<String, Object> usermodel = userlists.get(j);
                        if (!usermodel.get("dwmc").toString().equals(dwmc)) {
                            List<String> list1 = (List<String>) usermodel.get("tblist");
                            if (current == fhlist.size() - 1) {
                                String[] arr = (String[]) dwlist.subList(jg + current * fpgs, jg + current * fpgs + lastcount).toArray(new String[dwlist.subList(jg + current * fpgs, jg + (current + 1) * fpgs).size()]);
                                Collections.addAll(list1, arr);
                                usermodel.put("fpcount", Integer.parseInt(usermodel.get("fpcount").toString()) + lastcount);
                                current++;
                            } else {
                                List<String> listB = dwlist.subList(jg + (current + 1) * fpgs, jg + (current + 2) * fpgs);
                                List<List<String>> arrs = NewMethod(listA, listB); //替换清理
                                listA = arrs.get(0); //第一个list
                                listB = arrs.get(1); //第二个list
                                String[] arr = (String[]) listA.toArray(new String[listA.size()]);
                                Collections.addAll(list1, arr);

                                usermodel.put("fpcount", Integer.parseInt(usermodel.get("fpcount").toString()) + fpgs);
                                listA = listB;
                                current++;
                            }
                        }
                    }
                }
            }
            //endregion

            //region 5 list批量分配即可
            int c = 0;
            for (int i = 0; i < userlists.size(); i++) {
                Map<String, Object> model = userlists.get(i);
                parm.put("jl_username", model.get("username").toString());
                parm.put("jl_shr", model.get("realname").toString());
                parm.put("jl_fpdate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                parm.put("tbList", model.get("tblist"));
                List<String> list1 = (List<String>) model.get("tblist");
                if (!("").equals(list1) && list1.size() > 0 && !list1.isEmpty()) {
                    System.out.println(model.get("username").toString() + "分配图斑" + model.get("fpcount").toString() + "个，列表如下" + model.get("tblist"));
                    c += wpzfJlHcTaskMapper.addTaskUsergg(parm);
                }
            }
            //endregion

            return c;
        } catch (Exception ex) {
            return 0;
        }
    }

    private List<Map<String, Object>> GetUser(List<Map<String, Object>> jllists, String dwmc) {
        List<Map<String, Object>> jlist = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < jllists.size(); i++) {
            Map<String, Object> model = jllists.get(i);
            if (!model.get("dwmc").toString().equals(dwmc)) {
                jlist.add(model);
            }
        }
        return jlist;
    }

    private List<List<String>> NewMethod(List<String> list1, List<String> list2) {
        List<List<String>> arrs = new ArrayList<List<String>>();
        List<String> changeList = new ArrayList<String>();
        List<String> fchangeList = new ArrayList<String>();
        List<String> list3 = getCFList(list2); //查看list2 中是否有拆分图斑 list3
        if (list3.size() > 0) //下一个集合有拆分图斑
        {
            for (int j = 0; j < list3.size(); j++) {
                String oldtbbh = list3.get(j); //原始图斑编号
                String tbbh = oldtbbh.split("-")[0]; //获取拆分图斑编号 去掉-
                //list1.stream().filter(s -> null != s && s.contains(tbbh)).collect(Collectors.toList()); //从list1中查找是否存在
                List<String> list4 = getTbbhGLList(list1, tbbh); //从list1中查找是否存在
                if (list4.size() > 0)//存在
                {
                    changeList.add(oldtbbh); //list2 删掉 list1 增加
                    int cc = list1.size();
                    for (int m = 0; m < list1.size(); m++) //从list1中拿到一个补充回去 同时list1删掉一个
                    {
                        String bctbbh = list1.get(m);
                        if (!bctbbh.contains(("-"))) {
                            if (!fchangeList.contains(bctbbh)) {
                                fchangeList.add(bctbbh);//list2 增加 list1 删除
                                break;
                            }
                        }
                    }
                }
            }
        }
        //处理掉 增加和删除得
        if (fchangeList.size() > 0) {
            ListIterator<String> iterator = list1.listIterator();
            for (int zk = 0; zk < fchangeList.size(); zk++) {
                while (iterator.hasNext()) {
                    if (iterator.next() == fchangeList.get(zk)) {
                        iterator.set(changeList.get(zk));
                        break;
                    }
                }
            }
            for (int zm = 0; zm < changeList.size(); zm++) {
                iterator = list2.listIterator();
                while (iterator.hasNext()) {
                    if (iterator.next() == changeList.get(zm)) {
                        iterator.set(fchangeList.get(zm));
                        break;
                    }
                }
            }
        }
        arrs.add(list1);
        arrs.add(list2);
        return arrs;
    }

    private List<String> getCFList(List<String> list2) {
        List<String> cfList = new ArrayList<String>();
        for (int i = 0; i < list2.size(); i++) {
            String tbbh = list2.get(i);
            if (tbbh.contains("-") && !tbbh.contains(",")) //包含括号，不包含逗号的
            {
                cfList.add(tbbh);
            }

        }
        return cfList;
    }

    private List<String> getTbbhGLList(List<String> list1, String gltbbh) {
        List<String> glList = new ArrayList<String>();
        for (int i = 0; i < list1.size(); i++) {
            String tbbh = list1.get(i);
            if (tbbh.contains(gltbbh)) //包含括号，不包含逗号的
            {
                glList.add(tbbh);
            }
        }
        return glList;
    }

    @Override
    public List<Map<String, Object>> get_jl_pchlist(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.get_jl_pchlist(parm);
    }

    @Override
    public List<Map<String, Object>> get_jl_userlist(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.get_jl_userlist(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_tasklist(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_tasklist(parm);
    }

    @Override
    public Integer query_jl_tasklist_count(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_tasklist_count(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_task_Leftlist(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_task_Leftlist(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_Provs(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_Provs(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_Citys(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_Citys(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_tbbh_list(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_tbbh_list(parm);
    }

    @Override
    public List<Map<String, Object>> query_jl_static(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_jl_static(parm);
    }

    @Override
    public int query_jl_static_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfJlHcTaskMapper.query_jl_static_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public int query_jl_user_hcjg(Map<String, Object> parm) {
        List<Map<String, Object>> list = wpzfJlHcTaskMapper.query_jl_user_hcjg(parm);
        return list.size();
    }

    @Override
    public int query_not_fptb_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfJlHcTaskMapper.query_not_fptb_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }

    @Override
    public List<Map<String, Object>> query_wfp_xzq(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_wfp_xzq(parm);
    }

    @Override
    public Map<String, Object> queryTaskUnit(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.queryTaskUnit(parm);
    }

    @Override
    public Map<String, Object> query_user_unit(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_user_unit(parm);
    }

    @Override
    public List<Map<String, Object>> query_wfp_tb(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.query_wfp_tb(parm);
    }

    @Override
    public List<Map<String, Object>> query_tbsc_task_list(ModelMap model) {
        return wpzfJlHcTaskMapper.query_tbsc_task_list(model);
    }
    @Autowired
    CommonService commonService;
    @Override
    public Integer updateSubmitList(Map<String, Object> parms) {
        Integer rest = 0;
        List<Map<String, Object>> selectList = (List<Map<String, Object>>) parms.get("selectList");
        if (selectList != null) {
            for (Map<String, Object> map : selectList) {
                map.put("username", parms.get("username"));
                map.put("realname", parms.get("realname"));
                map.put("dwmc", parms.get("dwmc"));
                map.put("sftj", "是");

                map.put("sftj_submitdate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                if (wpzfJlHcTaskMapper.updateSubmit(map) > 0) {
                    rest += wpzfJlHcTaskMapper.updateJlSubmit(map);
                    Map<String, Object> tbbhModel = wpzfShTbMapper.querybytbbh(map);
                    if (tbbhModel != null) {
                        wpzfShTbMapper.deleteTb(map);
                    }
                    map.put("ywhj", "1");
                    //获取到该图斑得 jl_jlpf  如果为同意  进入 审核模块
                    map.put("thbh", map.get("tbbh").toString());
                    List<Map<String, Object>> list = wpzfJlHcTaskMapper.query_jl_user_hcjg(map);
                    if (list != null && list.size() > 0) {
                        String jl_jlpf = "";
                        Object o = list.get(0).get("jl_jlpf");
                        if (o != null) {
                            jl_jlpf = list.get(0).get("jl_jlpf").toString();
                        }

                        if (("同意").equals(jl_jlpf))  //则进入监理评分模块
                        {
                            map.put("adddate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                            try {
                                Map<String, Object> tbhcjgsm = commonService.getHcjgsmBytbbh(map);
                                if (tbhcjgsm != null) {
                                    map.put("hcjgsm", tbhcjgsm.get("hcjgsm").toString());
                                    map.put("jcmj", tbhcjgsm.get("txjcmj")!=null?tbhcjgsm.get("txjcmj"):0);
                                    map.put("dlrdgdmj", tbhcjgsm.get("dlrdgdmj")!=null?tbhcjgsm.get("dlrdgdmj"):0);
                                    map.put("tb_gdmj", tbhcjgsm.get("tb_gdmj")!=null?tbhcjgsm.get("tb_gdmj"):0);
                                    map.put("tb_jbntmj", tbhcjgsm.get("tb_qzjbntmj")!=null?tbhcjgsm.get("tb_qzjbntmj"):0);
                                    map.put("zphlxjc", tbhcjgsm.get("zphlxjc")!=null?tbhcjgsm.get("zphlxjc"):null);
                                    map.put("yxzpdl", tbhcjgsm.get("yxzpdl")!=null?tbhcjgsm.get("yxzpdl"):null);
                                }
                            }
                            catch (Exception ex)
                            {

                            }
                            wpzfShTbMapper.addShTb(map);
                        }
                    }
                }
            }
        }
        return rest;
    }

    @Override
    public List<Map<String, Object>> getUserTaskStatistics(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.getUserTaskStatistics(parm);
    }

    @Override
    public Integer getUserTaskStatisticsCount(Map<String, Object> parm) {
        return wpzfJlHcTaskMapper.getUserTaskStatisticsCount(parm);
    }

    @Override
    public int query_kc_count(Map<String, Object> parm) {
        Integer count = 0;
        Map<String, Object> map = wpzfJlHcTaskMapper.query_kc_count(parm);
        if (map != null) {
            count = ((Number) map.get("cnt")).intValue();
        }
        return count;
    }
}
